<template>
	<view class="content" @click="login">
		<image class="logo" src="/static/logo.png"></image>
		<view class="text-area">
			<text class="title">{{title}}</text>
		</view>
	</view>
</template>

<script>
	import {LoginByCode} from '@/api/service.js'

	export default {
		data() {
			return {
				title: 'Hello'
			}
		},
		onLoad() {

		},
		methods: {
			async getCode() {
				return new Promise((resolve, reject) => {
					uni.login({
						success(res) {
							if (res.code)
								resolve(res.code);
						},
						fail(res) {
							reject(res);
						}
					})
				})
			},
			async login() {
				return new Promise(async (resolve, reject) => {
					let code = await this.getCode()
					let res = await LoginByCode({
						code
					})
					if (res.status == 200 && res.data) {
						resolve(true)
						// store.commit('LOGIN', res.data)
					} else {
						resolve(false)
						console.log('登录失败!');
					}
				})
			}
		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
</style>
